import { Bot_msg } from "../../model/bot/bot_msg";
import { sendImage } from "../../model/bot/sendLocaImage";
import browser, { tempDir } from "../../model/browser/browser";
import server from "../../model/client/server";
import { mathType, packge } from "../../model/msgHandle/packge";
import skillAsay from "../../model/skillAsay";
import { style_default } from "../../style/default";

class index extends packge {

    constructor() {
        super()
    }
    init(): void {
        this.addMath(mathType.math_all, '技能帮助', ((msg: Bot_msg) => { this.help('技能',msg) }), this)
        this.addMath(mathType.math_start, '遗忘', ((msg: Bot_msg) => { this.destroy(msg) }), this)
        this.addMath(mathType.math_all, '技能', ((msg: Bot_msg) => { this.list(msg) }), this)
        this.addMath(mathType.math_start, '查看技能', ((msg: Bot_msg) => { this.look(msg) }), this)
        this.addMath(mathType.math_start, '技能改名', ((msg: Bot_msg) => { this.reName(msg) }), this)
    }
    async reName(msg: Bot_msg) {
        let info = this.cover_NumStr(msg.getContent(true));
        if (!info[0] || info.length != 2 || info[1].length < 2) {
            msg.repeText('技能改名:技能改名 + ID + 名称')
            return;
        }
        server.api('body/skill/Rename', { idx: info[0], name:info[1],url:'' }, msg)
    }


    async look(msg: Bot_msg) {
        let look = msg.getContent(true);
        if (look.length == 0) {
            msg.repeText('①查看技能指令:查看技能 + 技能ID\n②@机器人 + 技能名称')
            return;
        }
        let lookIdx = Number(look);
        if (isNaN(lookIdx)) {
            lookIdx = 0;
        }
        // server.api('body/SkillMore', { idx: lookIdx,name:look}, msg)
        server.api('body/skill/Look', { idx: lookIdx, name: look }, msg);

    }
    async list(msg: Bot_msg) {

        let req = await server.api('body/Skills', {}, msg)
        if (!req) {
            return;
        }
        let list = req.skList;
        let s = new style_default()
        s.setTitle('我的技能')
        for (let i = 0; i < list.length; i++) {
            const element = list[i];
            const from = element.from.length >= 1 ? `[${element.from}]` : ''
            s.addLine(`[${i + 1}]${from}${element.name}${element.cd?`🕜️未就绪(${element.cd}s)`:''}`)
        }
        s.help('技能帮助')
        msg.repeText(s.end())
    }
    /**
     * 销毁技能
     */
    destroy(msg: Bot_msg) {
        let idx = this.getNumber(msg.getContent());
        if (idx <= 0) {
            msg.repeText(`技能遗忘指令:遗忘 + 技能ID`);
            return;
        }
        server.api('body/skill/Destroy', { idx: idx }, msg)
    }
}
export default new index();